var init = function() {
	var latitude = $("#latitude").val();
	var longitude = $("#longitude").val();
    var center = new qq.maps.LatLng(latitude,longitude);
    map = new qq.maps.Map(document.getElementById('container'),{
        center: center,
        zoom: 15
    });
    
  	//创建标记
    var marker = new qq.maps.Marker({
        position: center,
        map: map
    });
  	
    //添加到提示窗
    var info = new qq.maps.InfoWindow({
        map: map
    });
    
    //获取标记的点击事件
    qq.maps.event.addListener(marker, 'click', function() {
        info.open();
        info.setContent('<div style="text-align:center;white-space:nowrap;'+
        'margin:10px;">地址：' + marker.getPosition() + '</div>');
    });
    
    //调用地址解析类
    geocoder = new qq.maps.Geocoder({
        complete : function(result){
        	//var tp = "";
        	//for(name in result.detail){
        	//	tp += name + "=" + result.detail[name] + "; ";
        	//}
        	
        	var loc = result.detail.location;
        	
            map.setCenter(loc);
            marker.setPosition(loc);
            marker.setMap(map);
            info.setPosition(marker);
            
            var latlng = loc.toString().split(",");
            
            $("#address").val(result.detail.address);
            $("#province").val(result.detail.addressComponents.province);
            $("#city").val(result.detail.addressComponents.city);
            $("#district").val(result.detail.addressComponents.district);
            $("#latitude").val(latlng[0]);
            $("#longitude").val(latlng[1]);
        }
    });
}

function codeAddress() {
    var address = document.getElementById("address").value;
    geocoder.getLocation(address);
}

function loadScript() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://map.qq.com/api/js?v=2.exp&key=WQJBZ-F5OKV-4HPPF-UHKNQ-7WSGV-QCBB3&libraries=drawing,geometry,autocomplete,convertor&callback=init"
	document.body.appendChild(script);
}
	